package com.ghck.message.event;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;

import com.alibaba.fastjson.JSON;
import com.ghck.message.util.PushUtil;

@Component
public class JpushNotificationListener implements ApplicationListener<JpushNotificationEvent>{

	Logger logger=LoggerFactory.getLogger(JpushNotificationListener.class);
	
	@Override
	public void onApplicationEvent(JpushNotificationEvent event) {
		logger.info("JpushNotificationListener begin,event is "+JSON.toJSONString(event));
		try{
			if(event==null||event.getNotification()==null){
				logger.error("event from JpushNotificationListener is illegal,event is {}",event);
				return;
			}
			PushUtil.sendNotification(event.getNotification());
		}catch(Exception e){
			logger.error("JpushNotificationListener error,err msg is {}",e.getMessage());
		}
	}

}
